﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Mancala.Net
{
    public class Board
    {
        private Dictionary<int, int> m_oppositePositionsMap = new Dictionary<int, int>();        

        public Board()
        {
            InitializeOppositePositionsMap();
        }

        private void InitializeOppositePositionsMap()
        {
            m_oppositePositionsMap.Add(0, 11);
            m_oppositePositionsMap.Add(1, 10);
            m_oppositePositionsMap.Add(2, 9);
            m_oppositePositionsMap.Add(3, 8);
            m_oppositePositionsMap.Add(4, 7);
            m_oppositePositionsMap.Add(5, 6);
            m_oppositePositionsMap.Add(6, 5);
            m_oppositePositionsMap.Add(7, 4);
            m_oppositePositionsMap.Add(8, 3);
            m_oppositePositionsMap.Add(9, 2);
            m_oppositePositionsMap.Add(10, 1);
            m_oppositePositionsMap.Add(11, 0);
        }

        public int GetOppositePositionIndex(int position)
        {
            return m_oppositePositionsMap[position];
        }

        static public int GetNumber(string s)
        {
            int index;

            try
            {
                index = int.Parse(s.Substring(s.Length - 2));
            }
            catch
            {
                index = int.Parse(s.Substring(s.Length - 1));
            }

            return index;
        }
    }
}
